package com.xs.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xs.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * (User)表数据库访问层
 *
 * @author makejava
 * @since 2022-08-22 16:42:39
 */
@Repository
@Mapper
public interface UserDao extends BaseMapper<User> {
    //按倒序查询5人
    @Select("select * from user where cover=0 order by id desc limit 5")
    List<User> recommandUser();

    //    查询浏览次数
    @Select("select SUM(a.readnumber) from article a  left join user u on a.uid = u.id where u.id = #{id} and a.cover=0")
    Integer findReadNumber(@Param("id") Integer id);

    //查询被收藏数量
    @Select("SELECT count(*) FROM collection c left join  user u on u.id = c.authorid where u.id = #{id}")
    Integer findCollectionNumber(@Param("id") Integer id);

    //根据文章id查询文章作者的信息
    @Select("select u.* from article a left join user u on a.uid = u.id where a.id = #{id} ")
    User findUserByArticleId(@Param("id")  Integer id);


}

